package com.com.knowledgepaymentmanagementsystem.controller.bill;

import com.com.knowledgepaymentmanagementsystem.pojo.bill.Bill;
import com.com.knowledgepaymentmanagementsystem.service.bill.BillService;
import com.com.knowledgepaymentmanagementsystem.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张攀
 * @version 1.0
 * @description: TODO
 * @date 2025/9/23 上午10:21
 */

@RestController
@CrossOrigin
@Api(tags = "订单管理")
@RequestMapping("/bill")
public class BillController {

    @Autowired
    private BillService billService;

    @ApiOperation(value = "查询订单",httpMethod = "POST",notes = "查询订单")
    @PostMapping("/find")
    public ResultUtil<List<Bill>> findBills(@RequestBody Bill bill){
        try {
            return new ResultUtil<>(200,"查询成功",billService.findBills(bill));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"查询失败");
        }
    }


    @ApiOperation(value = "新增订单",httpMethod = "POST",notes = "新增订单")
    @PostMapping("/insert")
    public ResultUtil insertBills(@RequestBody Bill bill){
        try {
            return new ResultUtil(200,"新增成功",billService.insertBills(bill));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"新增失败");
        }
    }

    @ApiOperation(value = "删除订单",httpMethod = "DELETE",notes = "删除订单")
    @DeleteMapping("/delete")
    public ResultUtil deleteBills(@RequestBody Integer id){
        try {
            billService.deleteBills(id);
            return new ResultUtil(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"删除失败");
        }
    }

    @ApiOperation(value = "修改订单",httpMethod = "PUT",notes = "修改订单")
    @PutMapping("/update")
    public ResultUtil updateBills(@RequestBody Bill bill){
        try {
            billService.updateBills(bill);
            return new ResultUtil(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500,"修改失败");
        }
    }
}
